//
//  ForgetPasswdViewController.m
//  DaFangYa
//
//  Created by design on 15/7/30.
//  Copyright (c) 2015年 HFKJ_LZQ. All rights reserved.
//

#import "ForgetPasswdViewController.h"

@interface ForgetPasswdViewController ()<UITextFieldDelegate>
{

    NSTimer *timer;
    int Second;
    UIImage *normalImage;
    UIImage *selectImage;
}
@end

@implementation ForgetPasswdViewController

- (void)viewDidLoad {
    self.titleForNav = @"忘记密码";
    self.isSupportSingleTapHideKeyboard = YES;
    [super viewDidLoad];
   
    UIButton *disMissBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 15, 60, 40)];
    [disMissBtn setImage:[UIImage imageNamed:@"arrow_white_left"] forState:UIControlStateNormal];
    disMissBtn.tag = 103;
    [disMissBtn addTarget:self action:@selector(disMissHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:disMissBtn];
    
    
    _phoneTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    _textCodeTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    [_phoneTextField setTextFieldColor:[UIColor blackColor] placeColor:[UIColor blackColor] andStr:@"请输入手机号"];
    [_textCodeTextField setTextFieldColor:[UIColor blackColor] placeColor:[UIColor blackColor] andStr:@"请输入验证码"];
//     _textCodeTextField.tintColor = [UIColor blackColor];
}
-(void)disMissHandle:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)btnClickedHandle:(UIButton *)sender {
    switch (sender.tag) {
        case 300:
        {
            //发送验证码
            if (![NSString isMobileNumber:_phoneTextField.text]) {
                [MBProgressHUD showHUDAddedTo:self.view WithString:@"请输入正确的手机号"];
            }
            else
            {
//                Second =60;
//                [timer invalidate];
//                timer=nil;
                [self checkPhoneIsRegister];
                
            }
        }
            break;
        case 301:
        {
            //保存并登录
            
            if (![NSString isMobileNumber:_phoneTextField.text]) {
                [MBProgressHUD showHUDAddedTo:self.view WithString:@"请输入正确的手机号"];
            }
            else  if ([NSString isEmpty:_textCodeTextField.text]) {
                [MBProgressHUD showHUDAddedTo:self.view WithString:@"请输入验证码"];
            }
           
            else
            {
//                [self checkPhoneIsRegister];
                [self findPasswdRequest];
            }
            
//            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
        }
            break;
            
        default:
            break;
    }
    
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.view endEditing:YES];
    return YES;
}

-(void)sendCheckCodeRequest
{
   
}

-(void)checkPhoneIsRegister
{
    // /reg/check/account
  
}
-(void)registerRequest
{
    //
//    NSDictionary *paramDic = [[NSDictionary alloc] initWithObjectsAndKeys:_phoneTextField.text,@"account",_passwdTextField.text,@"password",_textCodeTextField.text,@"phoneCode", nil];
    
}

-(void)findPasswdRequest
{
    NSDictionary *paramDic = [[NSDictionary alloc] initWithObjectsAndKeys:@"18616707730",@"phone",@"123456",@"pwd",@"lzq",@"nickname",@"111111",@"code",@"1",@"test", nil];
    [[CDAPIManager sharedManager] request_AllHandle_WithParams:paramDic andApiTag:KRegisterTag andIsSign:YES andBlock:^(id data, NSError *error,BOOL isSuccess){
        
        if (isSuccess) {
            
            Person *_person = [Person sharePerson];
            _person.userId = [data objectForKey:@"data"];//得到userid
        }
        else
        {
            
        }
    }];
    
}



- (void)repeats
{
    
//    if (Second >0)
//    {  --Second;
//        [self.sendBtn setBackgroundImage:selectImage forState:UIControlStateNormal];
//        self.sendBtn.titleLabel.text =[NSString stringWithFormat:@"重发(%i)s",Second];
//        [_sendBtn setTitle:[NSString stringWithFormat:@"重发(%i)s",Second] forState:UIControlStateNormal];
//        self.sendBtn.userInteractionEnabled =NO;
//        
//        
//        // [self.fasongyanzhenmaButton setTitle:[NSString stringWithFormat:@"重发(%i)s",Second] forState:UIControlStateNormal];
//        
//    }
//    else
//    {
//        [self.sendBtn setBackgroundImage:normalImage forState:UIControlStateNormal];
//        self.sendBtn.userInteractionEnabled =YES;
//        
//        [self.sendBtn setTitle:[NSString stringWithFormat:@"重新发送"] forState:UIControlStateNormal];
//        
//    }
    
}



- (void)loginRequest
{/* 13296729578  123456 */
    //登录校验都是 在头部信息里面去校验的。。通过能不能拿到用户信息去判断是不是调用登录成功
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
